

package jetbrains.buildServer.server.rest.data.util;

import java.util.Arrays;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class FilterConditionCheckerUtilTest {

  @Test
  public void testAnd() {
    FilterConditionChecker<Integer> filter = FilterConditionCheckerUtil.and(Arrays.asList(
      it -> it % 2 == 0,
      it -> it % 3 == 0,
      it -> it % 4 == 0
    ));

    assertTrue(filter.isIncluded(12));
    assertTrue(filter.isIncluded(0));
    assertFalse(filter.isIncluded(2));
    assertFalse(filter.isIncluded(3));
    assertFalse(filter.isIncluded(4));
    assertFalse(filter.isIncluded(1));
  }

  @Test
  public void testOr() {
    FilterConditionChecker<Integer> filter = FilterConditionCheckerUtil.or(Arrays.asList(
      it -> it % 2 == 0,
      it -> it % 3 == 0,
      it -> it % 4 == 0
    ));

    assertTrue(filter.isIncluded(12));
    assertTrue(filter.isIncluded(0));
    assertTrue(filter.isIncluded(2));
    assertTrue(filter.isIncluded(3));
    assertTrue(filter.isIncluded(4));
    assertFalse(filter.isIncluded(1));
  }
}